package com.example.demo.configer;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;

/**
 * @Description
 * @Author <a href="hedong.wu@baozun.com">wuhedong</a>
 * @Date 2020/5/26 15:47
 **/
@Configuration
@Data
@ConfigurationProperties(value = "canal")
public class CanalConfiguration {

    private String host;

    private int port;

    private String destination;

    private String userName;

    private String password;

    private String subscribe;

    private int batchSize;

    @Bean
    public CanalConnector getConnection(){
        CanalConnector connector = CanalConnectors.newSingleConnector(
                new InetSocketAddress(host, 11111),
                destination, userName, password);
        connector.connect();
        connector.subscribe(".*\\..*");
        connector.rollback();
        return connector;
    }

}
